package com.kimastrom.theGame.Model;

import android.util.Log;


public class BallCollision {
	//TODO fixa kollisionen
	public void collision(Ball a_ball, Map a_map) {
		a_ball.update();
		for (int x = 0; x < a_map.m_xTileCount; x += 1) {
            for (int y = 0; y < a_map.m_yTileCount; y += 1) {
            	if (a_map.m_tileGrid[x][y] > 0) {
            		//Log.i("collision", "x: "+String.valueOf(x));
            		//Log.i("collision", "y"+String.valueOf(y));
                    if(a_ball._ballY > y*20 - 20 && a_ball._ballY < y*20) {
                    	if(a_ball._ballX > x*20 && a_ball._ballX < x*20 + 20) {
                    		
                    		 if(a_ball._ballY > y*20 - 20 && a_ball._ballY < y*20) {
                             	if(a_ball._ballX > x*20 && a_ball._ballX < x*20 + 20) {
                             		
                             	}
                    		 }
                    		
                    		//
                    		if (a_ball._ballVelocityX > 0 && a_ball._ballVelocityY < 0) {	
                    			a_ball._ballVelocityY *= -1;
                    		} else if(a_ball._ballVelocityX > 0 && a_ball._ballVelocityY > 0){
                    			a_ball._ballVelocityX *= -1;
                    		} else if(a_ball._ballVelocityX < 0 && a_ball._ballVelocityY > 0){
                    			Log.i("collision", "insajjjd");
                    			a_ball._ballVelocityY *= -1;
                    		} else if(a_ball._ballVelocityX < 0 && a_ball._ballVelocityY < 0) {
                    			a_ball._ballVelocityX *= -1;
                    		}
                    	}
                    }
                }
            }
        }
	}
	
}
